package com.scoy.honeymei.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.scoy.honeymei.R;
import com.scoy.honeymei.bean.TravelOrderBean;
import com.scoy.honeymei.utils.GlideImgUtil;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ClassName: NormalAdapter$
 * @Description:
 * @Author: GaoZhan
 * @CreateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateRemark: 更新内容
 */
public class TravelMeAdapter extends RecyclerView.Adapter {
    private Context context;
    private ArrayList<TravelOrderBean> datalist;
    private TextView notv;
    private int tPos;

    public TravelMeAdapter(Context context, ArrayList<TravelOrderBean> datalist, TextView notv, int tPos) {
        this.context = context;
        this.datalist = datalist;
        this.notv = notv;
        this.tPos = tPos;
    }

    public interface OnOneClick {
        void oneClick(int pos);
    }

    OnOneClick onOneClick;

    public void setOnOneClick(OnOneClick onOneClick) {
        this.onOneClick = onOneClick;
    }

    public interface OnTwoClick {
        void twoClick(int pos);
    }

    OnTwoClick onTwoClick;

    public void setOnTwoClick(OnTwoClick onTwoClick) {
        this.onTwoClick = onTwoClick;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_travel_me, parent, false);
        return new TravelMeHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        TravelMeHolder travelHolder = (TravelMeHolder) holder;
        TravelOrderBean travelOrderBean = datalist.get(position);
        if (tPos == 0) {
            travelHolder.itlTopRl.setVisibility(View.GONE);
            travelHolder.itlTv4.setVisibility(View.GONE);
            travelHolder.itlDate2Tv.setVisibility(View.GONE);
            int stateswitch = travelOrderBean.getStateswitch();//1已处理，0未处理

            travelHolder.itlDateTv.setText(travelOrderBean.getAbouttime());
            if(stateswitch==1){
                travelHolder.itlSignIv.setImageResource(R.drawable.ic_review_ed);
            }else {
                travelHolder.itlSignIv.setImageResource(R.drawable.ic_review_pre);
            }

        } else {
            travelHolder.itlSignIv.setVisibility(View.GONE);
            travelHolder.itlTv1.setVisibility(View.GONE);
            travelHolder.itlDateTv.setVisibility(View.GONE);

            travelHolder.itlTime0Tv.setText(travelOrderBean.getCreatetime());
            travelHolder.itlDate2Tv.setText(travelOrderBean.getNum()+"人");

        }

        travelHolder.itlNameTv.setText(travelOrderBean.getName());
        GlideImgUtil.glidePic(context, travelOrderBean.getImage(), travelHolder.itlImgIv);
        travelHolder.itlTraveltypeTv.setText(travelOrderBean.getType_name());

        travelHolder.itemTravel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onOneClick != null) {
                    onOneClick.oneClick(position);
                }
            }
        });


    }

    @Override
    public int getItemCount() {
        int iCount = datalist == null ? 0 : datalist.size();
        if (iCount == 0) {
            notv.setVisibility(View.VISIBLE);
        } else {
            notv.setVisibility(View.GONE);
        }
        return iCount;
    }

    class TravelMeHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.itl_tv2)
        TextView itlTv2;
        @BindView(R.id.itl_time0_tv)
        TextView itlTime0Tv;
        @BindView(R.id.itl_top_rl)
        RelativeLayout itlTopRl;
        @BindView(R.id.itl_img_iv)
        ImageView itlImgIv;
        @BindView(R.id.itl_name_tv)
        TextView itlNameTv;
        @BindView(R.id.itl_tv0)
        TextView itlTv0;
        @BindView(R.id.itl_traveltype_tv)
        TextView itlTraveltypeTv;
        @BindView(R.id.itl_tv1)
        TextView itlTv1;
        @BindView(R.id.itl_date_tv)
        TextView itlDateTv;
        @BindView(R.id.itl_tv4)
        TextView itlTv4;
        @BindView(R.id.itl_date2_tv)
        TextView itlDate2Tv;
        @BindView(R.id.itl_sign_iv)
        ImageView itlSignIv;
        @BindView(R.id.item_travel)
        ConstraintLayout itemTravel;

        TravelMeHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
